package org.huawei.utils;

public class ByteUtil {

    /**
     * Convert bytes to hex string (all lower-case).
     *
     * @param bytes Input bytes.
     * @return Hex string.
     */
    public static String toHexString(byte[] bytes) {
        StringBuilder hexString = new StringBuilder();
        for (byte b : bytes) {
            // 将每个字节转换为两位的十六进制字符串
            String hex = String.format("%02x", b);
            hexString.append(hex);
        }
        return hexString.toString();
    }

    /**
     * Convert byte to hex string (all lower-case).
     *
     * @param b Input byte.
     * @return Hex string.
     */
    public static String toHex(byte b) {
        return toHexString(new byte[]{b});
    }
}
